/* ************************************************************************

   Copyright:

   License:

   Authors:

************************************************************************ */

/* ************************************************************************

#asset(mmclient/*)
#asset(qx/icon/${qx.icontheme}/16/*)
#asset(qx/icon/${qx.icontheme}/22/*)
#asset(qx/icon/${qx.icontheme}/32/*)

************************************************************************ */

/**
 * The GUI definition of the Map Medley client.
 */
qx.Class.define("mmclient.MapMedley",
{
  extend : qx.ui.container.Composite,


  /*
  *****************************************************************************
     CONSTRUCTOR
  *****************************************************************************
  */

  construct : function()
  {
    this.base(arguments);

    // Configure layout
    var layout = new qx.ui.layout.VBox;
    layout.setSeparator("separator-vertical");
    this.setLayout(layout);

    // Header
    this.add(this._createHeader());

    // Commands & Menu Bar
    this.__makeCommands();
    this.__menuBar = this.__makeMenuBar();
    this.add(this.__menuBar);
    
    // Tool Bar
    this.__toolBar = this.__makeToolBar();
    this.add(this.__toolBar);


    // Main Split Pane
    this.mainsplit = new qx.ui.splitpane.Pane("horizontal");
    this.add(this.mainsplit, {flex : 1});
    
    this._leftsplit = new qx.ui.splitpane.Pane("vertical");
    this._leftsplit.setDecorator(null);

    this._leftComposite = new qx.ui.container.Composite();
    this._leftComposite.setLayout(new qx.ui.layout.VBox(1));
    this._leftComposite.setBackgroundColor("#FFFFFF");

    this._layers = this.__makeTree();
    this._leftsplit.add(this._layers, 1);
    
    var mapMain = new mmclient.mapscript.MapObj;
    mapMain.setExtent(new mmclient.mapscript.RectObj);
    mapMain.setReferenceMap(new mmclient.mapscript.ReferenceMapObj);
    mapMain.getReferenceMap().setExtent(new mmclient.mapscript.RectObj);

    this._viewMain = new mmclient.MapView(mapMain);
    this._viewMain.setReferenceView(new mmclient.ReferenceView(this._viewMain));

    this._viewRef = this._viewMain.getReferenceView();
    this._viewRef.set({height:150});
    this._leftsplit.add(this._viewRef, 0);
    
    this._leftComposite.add(this._leftsplit, {flex: 1});
    this.mainsplit.add(this._leftComposite, 0);
    this.mainsplit.add(this._viewMain, 1);
  },


/*
  *****************************************************************************
     MEMBERS
  *****************************************************************************
  */

  members :
  {
    // ------------------------------------------------------------------------
    //   CONSTRUCTOR HELPERS
    // ------------------------------------------------------------------------
    
    // Hot keys: 
    __newCommand : null,
    __openCommand : null,
    __saveCommand : null,

    // Menu Bar:
    __menuPart : null,
    __fileMenu : null,
    __viewMenu : null,
    __scalePropMenu : null,
    __mapUntisMenu : null,
    __scaleUntisMenu : null,
    __screenUntisMenu : null,
    __layerMenu : null,
    __toolsMenu : null,
    __helpMenu : null,
    __userPart : null,
    __userMenu : null,
    __menuBar : null,

    // Tool Bar:
    __toolPart : null,
    __toolBar : null,
    
    // Mapping Layout:
    _layers : null,
    _viewRef : null,
    _leftsplit : null,
    _leftComposite : null,
    _viewMain : null,

    __debugTest : function()
    {
      this.debug("Debugging getMapImg service.");
      
      var self = this;

      var rpc = new qx.io.remote.Rpc("http://localhost/services/", "qooxdoo.mmserv");
      rpc.setCrossDomain(true);
      rpc.setTimeout(10000);

      var testJson = function(result, exc, id)
      {
        if (exc == null)
        {
          //alert("Result of async(" + id + ") call: " + result);
          self.debug("Red: " + result['r'] + " Green: " + result['g'] + " Blue: " + result['b']);
        }
        else
        {
          alert("Exception during async(" + id + ") call: " + exc);
        } 
      };

      rpc.callAsync(testJson, "testJson",
      {
        hexcolor   : "a2f4d8"
      });
    },

    __makeTree : function()
    {
      var tree = new qx.ui.tree.Tree().set({width:200});
      var root = this.configureTreeItem(new qx.ui.tree.TreeFolder(), "Untitled Map", "icon/16/places/folder.png", "icon/16/places/folder-open.png");
      root.setOpen(true);
      tree.setRoot(root);
      tree.setRootOpenClose(true);
      tree.setDraggable(true);
      tree.setDroppable(true);
      
      // One icon for selected and one for unselected states
      var te1 = this.configureTreeItem(new qx.ui.tree.TreeFile(), "countries_simpl");
      root.add(te1);

      var te2 = this.configureTreeItem(new qx.ui.tree.TreeFile(), "poi_crap");
      root.add(te2);
      
      var te3 = this.configureTreeItem(new qx.ui.tree.TreeFile(), "more junk");
      root.add(te3);

      tree.addListener("dragstart", function(e) {
        e.addAction("move");
      });
      
      tree.addListener("drop", function(e)
      {
        // Using the selection sorted by the original index in the list
        var sel = this.getSortedSelection();

        // This is the original target hovered
        var orig = e.getOriginalTarget();
        if (!(orig instanceof qx.ui.tree.TreeFile))
        {
          orig = this.getTreeItem(orig);
        }

        if (orig instanceof qx.ui.tree.TreeFile)
        {
          for (var i=0, l=sel.length; i<l; i++)
          {
            if (sel[i] instanceof qx.ui.tree.TreeFile && sel[i] != orig)
            {
              // Insert before the marker
              orig.getParent().addBefore(sel[i], orig);
        
              // Recover selection as it gets lost during child move
              this.addToSelection(sel[i]);
            }
          }
        }
      });


      return tree;
    },
    
    configureTreeItem : function(treeItem, vLabel, vIcon, vIconOpen)
    {
      // A left-justified icon
      if (Math.floor(Math.random() * 4) == 0 && vLabel != "Untitled Map") {
        var img = new qx.ui.basic.Image("icon/16/actions/media-record.png");
        treeItem.addWidget(img);
      } else {
        treeItem.addWidget(new qx.ui.core.Spacer(16, 16));
      }
      
      // Here's our indentation and tree-lines
      treeItem.addSpacer();

      if (treeItem instanceof qx.ui.tree.TreeFolder) {
        treeItem.addOpenButton();
      }
      
      // The standard tree icon follows
      treeItem.addIcon();
      treeItem.setIcon(arguments.length >= 3 ? vIcon : "icon/16/places/user-desktop.png");
      
      // The standard tree icon-open follows
      if (treeItem instanceof qx.ui.tree.TreeFolder)
      {      
        treeItem.setIconOpened(arguments.length >= 4 ? vIconOpen : "icon/16/places/user-desktop.png");
      }
      
      if (vLabel != "Untitled Map")
      {
        // A checkbox comes right after the tree icon
        var checkbox = new qx.ui.form.CheckBox();
        checkbox.setFocusable(false);
        treeItem.addWidget(checkbox);
      }

      // The label
      treeItem.addLabel(vLabel);

      return treeItem;
    },
        

    /**
     * Creates the application header.
     */
    _createHeader : function()
    {
      var layout = new qx.ui.layout.HBox();
      var header = new qx.ui.container.Composite(layout);
      header.setBackgroundColor("#CC0000");
      header.setTextColor("#FFFFFF");

      var title = new qx.ui.basic.Label("Map Medley Client version 0.1.999.0");
      var f11 = new qx.ui.basic.Label("View at fullscreen (F11)");

      header.add(title);
      header.add(new qx.ui.core.Spacer, {flex : 1});
      header.add(f11);

      return header;
    },
    
    
    /**
     * Creates the menu shortcuts.
     */    
    __makeCommands : function()
    {
      this.__newCommand = new qx.ui.core.Command("Ctrl+N");
      //this.__newCommand.addListener("execute", this.debugCommand);

      this.__openCommand = new qx.ui.core.Command("Ctrl+O");
      //this.__openCommand.addListener("execute", this.debugCommand);

      this.__saveCommand = new qx.ui.core.Command("Ctrl+S");
      //this.__saveCommand.addListener("execute", this.debugCommand);
    },


    /**
     * Creates the menu bar.
     */    
    __makeMenuBar : function()
    {
      var bar = new qx.ui.toolbar.ToolBar();
      var menuPart = new qx.ui.toolbar.Part;
      this.__menuPart = menuPart;
      bar.add(menuPart);

      // FILE MENU
      // -----------------------------------------------------
      var fileMenu = new qx.ui.menu.Menu;
      this.__fileMenu = fileMenu;

      var newButton = new qx.ui.menu.Button("New", "icon/16/actions/document-new.png");
      var openButton = new qx.ui.menu.Button("Open...", "icon/16/actions/document-open.png");
      var renameButton = new qx.ui.menu.Button("Rename...", "icon/16/actions/document-save-as.png");

      fileMenu.add(newButton);
      fileMenu.add(openButton);
      fileMenu.addSeparator();      
      fileMenu.add(renameButton);

      var fileButton = new qx.ui.toolbar.MenuButton("File", null, fileMenu);
      menuPart.add(fileButton);


      // VIEW MENU
      // -----------------------------------------------------
      var viewMenu = new qx.ui.menu.Menu;
      this.__viewMenu = viewMenu;

      var fullButton = new qx.ui.menu.Button("Zoom to Full Extent", "mmclient/icon/16/tools/zoom-full.png");
      var activeButton = new qx.ui.menu.Button("Zoom to Active Layer", "mmclient/icon/16/tools/zoom-layer.png");
      var scaleCheckBox = new qx.ui.menu.CheckBox("Scale Bar");
      scaleCheckBox.setValue(true);
      
      
      var scalePropMenu = new qx.ui.menu.Menu;
      this._scalePropMenu = scalePropMenu;

      var mapUnitsMenu = new qx.ui.menu.Menu;
      this.__mapUnitsMenu = mapUnitsMenu;
      var mu_decDegRadioButton = new qx.ui.menu.RadioButton("Decimal Degrees");
      mu_decDegRadioButton.setValue(true);
      var mu_feetRadioButton = new qx.ui.menu.RadioButton("Feet");
      var mu_metersRadioButton = new qx.ui.menu.RadioButton("Meters");
      mapUnitsMenu.add(mu_decDegRadioButton);
      mapUnitsMenu.add(mu_feetRadioButton);
      mapUnitsMenu.add(mu_metersRadioButton);
      // Map Units Radio Group
      var mapUnitsGroup = new qx.ui.form.RadioGroup;
      mapUnitsGroup.add(mu_decDegRadioButton, mu_feetRadioButton, mu_metersRadioButton);
      var mapUnitsButton = new qx.ui.menu.Button("Map Units", null, null, mapUnitsMenu);
      
      var scaleUnitsMenu = new qx.ui.menu.Menu;
      this.__scaleUnitsMenu = scaleUnitsMenu;
      var scaleu_feetRadioButton = new qx.ui.menu.RadioButton("Feet");
      var scaleu_metersRadioButton = new qx.ui.menu.RadioButton("Meters");
      scaleu_metersRadioButton.setValue(true);
      var scaleu_kilometersRadioButton = new qx.ui.menu.RadioButton("Kilometers");
      var scaleu_milesRadioButton = new qx.ui.menu.RadioButton("Miles");
      scaleUnitsMenu.add(scaleu_feetRadioButton);
      scaleUnitsMenu.add(scaleu_metersRadioButton);
      scaleUnitsMenu.add(scaleu_kilometersRadioButton);
      scaleUnitsMenu.add(scaleu_milesRadioButton);
      // Scale Units Radio Group
      var scaleUnitsGroup = new qx.ui.form.RadioGroup;
      scaleUnitsGroup.add(scaleu_feetRadioButton, scaleu_metersRadioButton, scaleu_kilometersRadioButton, scaleu_milesRadioButton);
      var scaleUnitsButton = new qx.ui.menu.Button("Scale Units", null, null, scaleUnitsMenu);
      
      var screenUnitsMenu = new qx.ui.menu.Menu;
      this.__screenUnitsMenu = screenUnitsMenu;
      var screenu_centimetersRadioButton = new qx.ui.menu.RadioButton("Centimeters");
      screenu_centimetersRadioButton.setValue(true);
      var screenu_inchesRadioButton = new qx.ui.menu.RadioButton("Inches");
      screenUnitsMenu.add(screenu_centimetersRadioButton);
      screenUnitsMenu.add(screenu_inchesRadioButton);
      // Screen Units Radio Group
      var screenUnitsGroup = new qx.ui.form.RadioGroup;
      screenUnitsGroup.add(screenu_centimetersRadioButton, screenu_inchesRadioButton);
      var screenUnitsButton = new qx.ui.menu.Button("Screen Units", null, null, screenUnitsMenu);

      scalePropMenu.add(mapUnitsButton);
      scalePropMenu.addSeparator();
      scalePropMenu.add(scaleUnitsButton);
      scalePropMenu.add(screenUnitsButton);
      var scalePropButton = new qx.ui.menu.Button("Scale Bar Properties", null, null, scalePropMenu);
      
      
      viewMenu.add(fullButton);
      viewMenu.add(activeButton);
      viewMenu.addSeparator();
      viewMenu.add(scaleCheckBox);
      viewMenu.add(scalePropButton);

      var viewButton = new qx.ui.toolbar.MenuButton("View", null, viewMenu);
      menuPart.add(viewButton);


      // LAYER MENU
      // -----------------------------------------------------
      var layerMenu = new qx.ui.menu.Menu;
      this.__layerMenu = layerMenu;

      var addButton = new qx.ui.menu.Button("Add Layer...", "icon/16/actions/list-add.png");
      var removeButton = new qx.ui.menu.Button("Remove Layer", "icon/16/actions/list-remove.png");
      var propButton = new qx.ui.menu.Button("Layer Properties...", "icon/16/actions/document-properties.png");

      layerMenu.add(addButton);
      layerMenu.add(removeButton);
      layerMenu.addSeparator();
      layerMenu.add(propButton);

      var layerButton = new qx.ui.toolbar.MenuButton("Layer", null, layerMenu);
      menuPart.add(layerButton);


      // TOOLS MENU
      // -----------------------------------------------------
      var toolsMenu = new qx.ui.menu.Menu;
      this.__toolsMenu = toolsMenu;

      var panButton = new qx.ui.menu.Button("Pan", "icon/16/devices/input-mouse.png");
      var zoomInButton = new qx.ui.menu.Button("Zoom In", "icon/16/actions/zoom-in.png");
      var zoomOutButton = new qx.ui.menu.Button("Zoom Out", "icon/16/actions/zoom-out.png");
      var measDistButton = new qx.ui.menu.Button("Measure Distance", "icon/16/status/image-missing.png");
      var measAreaButton = new qx.ui.menu.Button("Measure Area", "icon/16/status/image-missing.png");

      panButton.addListener("execute", function(e)
      {
        if (this.__toolPart.getChildren()[5] instanceof qx.ui.toolbar.RadioButton)
        {
          this.__toolPart.getChildren()[5].setValue(true);
          this._viewMain.changeTool(mmclient.MapView.TOOL_PAN);
        }
      }, this);
      zoomInButton.addListener("execute", function(e)
      {
        if (this.__toolPart.getChildren()[6] instanceof qx.ui.toolbar.RadioButton)
        {
          this.__toolPart.getChildren()[6].setValue(true);
          this._viewMain.changeTool(mmclient.MapView.TOOL_ZOOMIN);
        }
      }, this);
      zoomOutButton.addListener("execute", function(e)
      {
        if (this.__toolPart.getChildren()[7] instanceof qx.ui.toolbar.RadioButton)
        {
          this.__toolPart.getChildren()[7].setValue(true);
          this._viewMain.changeTool(mmclient.MapView.TOOL_ZOOMOUT);
        }
      }, this);
      measDistButton.addListener("execute", function(e)
      {
        if (this.__toolPart.getChildren()[8] instanceof qx.ui.toolbar.RadioButton)
        {
          this.__toolPart.getChildren()[8].setValue(true);
        }
      }, this);
      measAreaButton.addListener("execute", function(e)
      {
        if (this.__toolPart.getChildren()[9] instanceof qx.ui.toolbar.RadioButton)
        {
          this.__toolPart.getChildren()[9].setValue(true);
        }
      }, this);

      toolsMenu.add(panButton);
      toolsMenu.add(zoomInButton);
      toolsMenu.add(zoomOutButton);
      toolsMenu.add(measDistButton);
      toolsMenu.add(measAreaButton);

      var toolsButton = new qx.ui.toolbar.MenuButton("Tools", null, toolsMenu);
      menuPart.add(toolsButton);


      // HELP MENU
      // -----------------------------------------------------
      var helpMenu = new qx.ui.menu.Menu;
      this.__helpMenu = helpMenu;

      var contentsButton = new qx.ui.menu.Button("Help Contents...", "icon/16/apps/utilities-help.png");
      var aboutButton = new qx.ui.menu.Button("About Map Medley...", "icon/16/status/dialog-information.png");

      helpMenu.add(contentsButton);
      helpMenu.addSeparator();
      helpMenu.add(aboutButton);

      var helpButton = new qx.ui.toolbar.MenuButton("Help", null, helpMenu);

      contentsButton.addListener("click", function(e) {
        window.open("http://localhost/wiki/index.php/Map_Medley_Client:Help_Contents");
      });
      
      aboutButton.addListener("click", function(e) {
        mmclient.dialog.Dialog.alert("<b>Map Medley Client</b> version 0.1.999.0<br/>Copyright &copy; 2011 Brant Anderson");
      });
      menuPart.add(helpButton);
      
      
      // USER MENU
      // -----------------------------------------------------
      bar.addSpacer();
      var userPart = new qx.ui.toolbar.Part;
      this.__userPart = userPart;
      bar.add(userPart);
      
      var userMenu = new qx.ui.menu.Menu;
      this.__userMenu = userMenu;
      
      var profileButton = new qx.ui.menu.Button("Profile", "icon/16/emotes/face-smile.png");
      var logoutButton = new qx.ui.menu.Button("Logout", "icon/16/actions/application-exit.png");
      
      logoutButton.addListener("execute", function(e)
      {
        var rpc = new qx.io.remote.Rpc("http://localhost/services/", "qooxdoo.mmserv");
        rpc.setCrossDomain(true);
        rpc.setTimeout(10000);
  
        var logout_callback = function(result, exc)
        {
          if (exc == null)
          {
            //alert("Result of async call: " + result);

            qx.core.Init.getApplication().getRoot().removeAll();
            qx.core.Init.getApplication().setUsername("");

            // Log into the system
            qx.core.Init.getApplication().login = new mmclient.Login;
            qx.core.Init.getApplication().getRoot().add(qx.core.Init.getApplication().login, {edge:0});
            qx.core.Init.getApplication().login.createLogin();
          }
          else
          {
            alert("Exception during async call: " + exc);
          }
        };
  
        rpc.callAsync(logout_callback, "logout");
      }, this);
      
      userMenu.add(profileButton);
      userMenu.addSeparator();
      userMenu.add(logoutButton);

      var userButton = new qx.ui.toolbar.MenuButton(qx.core.Init.getApplication().getUsername(), null, userMenu);
      userPart.add(userButton);
      
      // DONE
      // -----------------------------------------------------

      return bar;
    },
    
    
    /**
     * Creates the tool bar.
     */    
    __makeToolBar : function()
    {
      var bar = new qx.ui.toolbar.ToolBar();
      var toolPart = new qx.ui.toolbar.Part;
      this.__toolPart = toolPart;
      bar.add(toolPart);
      
      var refreshTip = new qx.ui.tooltip.ToolTip("<b>Refresh:</b><br />Refresh the map view.", "icon/16/actions/view-refresh.png");
      refreshTip.setRich(true);
      var refreshButton = new qx.ui.toolbar.Button("Refresh", "icon/22/actions/view-refresh.png");
      refreshButton.setToolTip(refreshTip);

      var fullTip = new qx.ui.tooltip.ToolTip("<b>Zoom Full:</b><br />Zoom to full extent view.", "mmclient/icon/16/tools/zoom-full.png");
      fullTip.setRich(true);
      var fullButton = new qx.ui.toolbar.Button("Zoom Full", "mmclient/icon/22/tools/zoom-full.png");
      fullButton.setToolTip(fullTip);
      
      var layerTip = new qx.ui.tooltip.ToolTip("<b>Zoom Layer:</b><br />Zoom to full layer view.", "mmclient/icon/16/tools/zoom-layer.png");
      layerTip.setRich(true);
      var layerButton = new qx.ui.toolbar.Button("Zoom Layer", "mmclient/icon/22/tools/zoom-layer.png");
      layerButton.setToolTip(layerTip);
      
      var panTip = new qx.ui.tooltip.ToolTip("<b>Pan / Recenter:</b><br />Drag map to pan. Click map to recenter.", "icon/16/devices/input-mouse.png");
      panTip.setRich(true);
      var panRadioButton = new qx.ui.toolbar.RadioButton("Pan / Recenter", "icon/22/devices/input-mouse.png");
      panRadioButton.setToolTip(panTip);
      
      var zoomInTip = new qx.ui.tooltip.ToolTip("<b>Zoom In:</b><br />Drag map to zoom to area. Click map to zoom in.", "icon/16/actions/zoom-in.png");
      zoomInTip.setRich(true);
      var zoomInRadioButton = new qx.ui.toolbar.RadioButton("Zoom In", "icon/22/actions/zoom-in.png");
      zoomInRadioButton.setToolTip(zoomInTip);

      var zoomOutTip = new qx.ui.tooltip.ToolTip("<b>Zoom Out:</b><br />Click map to zoom out.", "icon/16/actions/zoom-out.png");
      zoomOutTip.setRich(true);      
      var zoomOutRadioButton = new qx.ui.toolbar.RadioButton("Zoom Out", "icon/22/actions/zoom-out.png");
      zoomOutRadioButton.setToolTip(zoomOutTip);

      var measDistTip = new qx.ui.tooltip.ToolTip("<b>Measure Distance:</b><br />Click on map to place points.", "icon/16/status/image-missing.png");
      measDistTip.setRich(true);
      var measDistRadioButton = new qx.ui.toolbar.RadioButton("Measure Distance", "icon/22/status/image-missing.png");
      measDistRadioButton.setToolTip(measDistTip);
      
      var measAreaTip = new qx.ui.tooltip.ToolTip("<b>Measure Area:</b><br />Click on map to place points.", "icon/16/status/image-missing.png");
      measAreaTip.setRich(true);
      var measAreaRadioButton = new qx.ui.toolbar.RadioButton("Measure Area", "icon/22/status/image-missing.png");
      measAreaRadioButton.setToolTip(measAreaTip); 

      toolPart.add(refreshButton);
      toolPart.addSeparator();
      toolPart.add(fullButton);
      toolPart.add(layerButton);
      toolPart.addSeparator();
      toolPart.add(panRadioButton);
      toolPart.add(zoomInRadioButton);
      toolPart.add(zoomOutRadioButton);
      toolPart.add(measDistRadioButton);
      toolPart.add(measAreaRadioButton);
      toolPart.setShow("icon");
      
      // Tools Radio Group
      var toolsGroup = new qx.ui.form.RadioGroup;
      toolsGroup.add(panRadioButton, zoomInRadioButton, zoomOutRadioButton,
                    measDistRadioButton, measAreaRadioButton);

      panRadioButton.addListener("execute", function(e)
      {
        if (this.__toolPart.getChildren()[5] instanceof qx.ui.toolbar.RadioButton)
        {
          this.__toolPart.getChildren()[5].setValue(true);
          this._viewMain.changeTool(mmclient.MapView.TOOL_PAN);
        }
      }, this);
      zoomInRadioButton.addListener("execute", function(e)
      {
        if (this.__toolPart.getChildren()[6] instanceof qx.ui.toolbar.RadioButton)
        {
          this.__toolPart.getChildren()[6].setValue(true);
          this._viewMain.changeTool(mmclient.MapView.TOOL_ZOOMIN);
        }
      }, this);
      zoomOutRadioButton.addListener("execute", function(e)
      {
        if (this.__toolPart.getChildren()[7] instanceof qx.ui.toolbar.RadioButton)
        {
          this.__toolPart.getChildren()[7].setValue(true);
          this._viewMain.changeTool(mmclient.MapView.TOOL_ZOOMOUT);
        }
      }, this);
      measDistRadioButton.addListener("execute", function(e)
      {
        if (this.__toolPart.getChildren()[8] instanceof qx.ui.toolbar.RadioButton)
        {        
          this.__toolPart.getChildren()[8].setValue(true);
          this.__debugTest();
        }
      }, this);
      measAreaRadioButton.addListener("execute", function(e)
      {
        if (this.__toolPart.getChildren()[9] instanceof qx.ui.toolbar.RadioButton)
        {
          this.__toolPart.getChildren()[9].setValue(true);
        }
      }, this);
      
      bar.add(toolPart);
      
      return bar;
    }
  },


  /*
  *****************************************************************************
     DESTRUCTOR
  *****************************************************************************
  */

  destruct : function()
  {
    //this.widgets = this.tests = this._sampleToTreeNodeMap = this.tree = this.logelem = null;
    this._disposeObjects(
    "__newCommand",
    "__openCommand",
    "__saveCommand",
    "__menuPart",
    "__fileMenu",
    "__viewMenu",
    "__scalePropMenu",
    "__mapUntisMenu",
    "__scaleUntisMenu",
    "__screenUntisMenu",
    "__layerMenu",
    "__toolsMenu",
    "__helpMenu",
    "__userPart",
    "__userMenu",
    "__menuBar",
    "__toolPart",
    "__toolBar",
    "_leftComposite",
    "_viewMain");
  }
});
